package com.bc.util;

import java.io.InputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 用于加载Context路径中的文件
 * @author Administrator
 *
 */
public final class ConfigLoader {
	private static Log log = LogFactory.getLog(ConfigLoader.class);
	
	private ConfigLoader(){}
	
	/**
	 * 加载Context路径中的文件
	 * @param name 文件名，包括文件路径
	 * @return
	 * @throws SystemRunException
	 */
	public static InputStream loadConfig(String name) throws Exception{
		InputStream stream = null;
		name = (name.startsWith("/"))? name.substring(1) : name;
		ClassLoader loader = Thread.currentThread().getContextClassLoader();
		stream = loader.getResourceAsStream(name);
		if (stream == null){
			throw new Exception();
		}
		if (log.isInfoEnabled())log.info("load config file " + name + " success");
		return stream;
	}
}
